﻿Public Partial Class Vessel_Popup
    Inherits System.Web.UI.Page


    Dim clsGet As New ClassFunctionGetData
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            LoadData("XXXX", "", "", "", "", "")
        End If
    End Sub

    Private Sub LoadData(ByVal Booking_no As String, ByVal Vehicle_Text As String, ByVal Agent As String, ByVal DateFrom As String, ByVal DateTo As String, ByVal PORT As String)
        Dim dtCus As DataSet = clsGet.Get_BookingFOrOTher(Booking_no, Vehicle_Text, DateFrom, DateTo, Agent, PORT)
        gridCustomer.DataSource = dtCus
        gridCustomer.DataBind()

    End Sub

    Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim DateFrom As String = ""
        Dim DateTo As String = ""
        If (txtDate.Text.Trim() <> "") Then
            DateFrom = txtDate.Text.Split(" ")(2) & CDate(ClassFunctionGetData.CDateT(txtDate.Text)).ToString("MMdd")
            If (txtDateTo.Text.Trim() <> "") Then
                DateTo = txtDateTo.Text.Split(" ")(2) & CDate(ClassFunctionGetData.CDateT(txtDateTo.Text)).ToString("MMdd")
            Else
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('กรุณาทำการระบุ LAY CAN ให้ถุกต้อง !!');", True)
                Exit Sub
            End If
        Else
            If (txtDateTo.Text.Trim() <> "") Then
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " alert('กรุณาทำการระบุ LAY CAN ให้ถุกต้อง !!');", True)
                Exit Sub
            End If
        End If
        LoadData(txtBooking.Text, txtVessel.Text, txtAGENT.Text, DateFrom, DateTo, ddlPORT.SelectedValue)
    End Sub

    Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " parent.closeModal('C');", True)
    End Sub

    Private Sub gridCustomer_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridCustomer.RowCommand
        Dim Index As Integer = Convert.ToInt32(e.CommandArgument)
        If e.CommandName = "Edit" Then
            Session("VESSEL_OTHER") = gridCustomer.DataKeys(Index).Values("Booking_no") & "-" & gridCustomer.DataKeys(Index).Values("Vehicle_Text")
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " parent.closeModal('C');", True)
        End If
    End Sub

    Private Sub gridCustomer_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridCustomer.RowDataBound
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            If (gridCustomer.DataKeys(e.Row.RowIndex).Values("Date_From") & "" <> "") Then
                If (gridCustomer.DataKeys(e.Row.RowIndex).Values("Date_From") & "" = gridCustomer.DataKeys(e.Row.RowIndex).Values("Date_To") & "") Then
                    e.Row.Cells(2).Text = gridCustomer.DataKeys(e.Row.RowIndex).Values("Date_To")
                Else
                    e.Row.Cells(2).Text = gridCustomer.DataKeys(e.Row.RowIndex).Values("Date_From").ToString.Substring(0, 2) & "-" & gridCustomer.DataKeys(e.Row.RowIndex).Values("Date_To")
                End If
            End If
        End If
    End Sub

    Private Sub gridCustomer_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gridCustomer.RowEditing

    End Sub

    Private Sub MainPage_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Dim ds As DataSet = Session("UserData")
        If Not (ds Is Nothing) Then
            Page.MasterPageFile = clsGet.GetMaster_Page(ds.Tables(0).Rows(0).Item("User_Name").ToString(), "")
        End If
    End Sub

End Class